/*
 Copyright (c) 2012 by karmaleaving@qq.com. All rights RESERVED.
 */
#ifndef __STD_UTILITY_H_VERSION_KL__
#define __STD_UTILITY_H_VERSION_KL__
#define _USE_KL_EXTRA
#include "throw.h"

// STD_NAMESPACE {
#define KL kl
#define KL_BEGIN namespace KL {
#define KL_END   }
// STD_NAMESPACE }
// NEST_TYPE {
#define KL_TYPE_DEFINE(Type) \
typedef Type value_type; \
typedef value_type* pointer; \
typedef const value_type* const_pointer; \
typedef value_type& reference; \
typedef const value_type& const_reference; \
typedef int diff_type; \
typedef diff_type difference_type; \
typedef unsigned int size_type 
// NEST_TYPE }

#define _KL_USE_BASIC_ALGORITHM_
KL_BEGIN
#ifdef _KL_USE_BASIC_ALGORITHM_
// FUNCTION swap {
template<typename Type>
inline void swap(Type &left, Type &right)
{
	//if(&left == &right) return;
	Type temp = left;
	left = right;
	right = temp;
}
// FUNCTION swap }
// FUNCTION operator compare {
template<typename TypeL, typename TypeR>
inline bool operator > (TypeL const &left, TypeR const &right)
{
	return right < left;
}
template<typename TypeL, typename TypeR>
inline bool operator >= (TypeL const &left, TypeR const &right)
{
	return !(left < right);
}
template<typename TypeL, typename TypeR>
inline bool operator <= (TypeL const &left, TypeR const &right)
{
	return !(right < left);
}
template<typename TypeL, typename TypeR>
inline bool operator != (TypeL const &left, TypeR const &right)
{
	return !(left == right);
}
// FUNCTION operator compare }
// FUNCTION operator assign {
template<typename TypeL, typename TypeR>
inline TypeL & operator +=(TypeL &left, TypeR const &right)
{
	left = left + right;
	return left;
}
template<typename TypeL, typename TypeR>
inline TypeL & operator -=(TypeL &left, TypeR const &right)
{
	left = left + right;
	return left;
}
// FUNCTION operator assign {
// CLASS pair {
template<typename Type1, typename Type2>
struct pair
{
	typedef Type1 first_type;
	typedef Type2 second_type;
	first_type first;
	second_type second;
public:
	pair() : first(first_type()), second(second_type())
	{
	}
	template<typename First, typename Second>
	pair(First const &value1, Second const &value2)
	: first(value1), second(value2)
	{
	}
	template<typename First, typename Second>
	pair(pair<First, Second> const &o)
	: first(o.first), second(o.second)
	{
	}
	template<typename Pair>
	pair(Pair const &o)
	: first(o.first), second(o.second)
	{
	}
	void swap(pair &o)
	{
		if(this != &o)
		{
			swap(this->first, o.first);
			swap(this->second, o.second);
		}
	}
	template<typename First, typename Second>
	bool operator < (KL::pair<First, Second> const &right)
	{
		return first < right.first || 
		(!(right.first < first) && second < right.second);
	}
	template<typename First, typename Second>
	bool operator == (KL::pair<First, Second> const &right)
	{
		return first == right.first && second == right.second;
	}
};
// CLASS pair }
// FUNCTION swap make_pair (for pair) {
template<typename First, typename Second>
void swap(pair<First, Second> &left, pair<First, Second> &right)
{
	left.swap(right);
}
template<typename First, typename Second>
pair<First, Second> make_pair(First const &first, Second const &second)
{
	return pair<First, Second>(first, second);
}
// FUNCTION swap make_pair (for pair) }
#endif //_KL_USE_BASIC_ALGORITHM_
KL_END

#endif //__STD_UTILITY_H_VERSION_KL__
